package ar.uba.fi.tonyvaliente.commands;

import ar.uba.fi.tonyvaliente.documents.CreateIndexResult;
import ar.uba.fi.tonyvaliente.documents.DocumentManager;

public class CleanCommand extends Command {

	private boolean recognized;

	public CleanCommand(String[] args) {
		super(args);

		recognized = false;

		if (args.length > 0) {
			String command = args[0];
			command = command.toLowerCase();
			if (command.equals("-clean")) {
				recognized = true;
			}
		}
	}

	private CommandResult clean() {
		CommandResult cleanResult = DocumentManager.clean();
		if (cleanResult.isSuccess())
			return CommandResult.EXECUTE_SUCCESSFULLY;
		else
			return new CommandResult(true, false, cleanResult
					.getMessage());
	}

	public CommandResult execute() {
		if (!recognized){
			return CommandResult.NOT_RECOGNIZED;
		}
		
		return clean();
	}

	public String getSignature() {
		return "-clean";
	}

	public String getDescription() {
		return "Cleans the index directory";
	}

	public String[] getExamples() {
		return new String[] { "-clean" };
	}
}
